package com.wkck.controller;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.wkck.domain.Resume;
import com.wkck.service.ResumeService;
import com.wkck.utils.Code;
import com.wkck.utils.Msg;
import com.wkck.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/resumes")
@Slf4j
public class ResumeController {

    @Resource
    private ResumeService resumeService;

    /**
     * 根据用户的id得到该用户的简历信息
     * @param id
     * @return
     */

    @GetMapping("/{id}")
//    @Cacheable(value = "ResumeMsgById",key = "#id")
    public Result getResumeMsgById(@PathVariable Integer id){
        return new Result(Code.SELECT_OK,resumeService.getResumeMessageById(id), Msg.SELECT_OK);
    }

    /**
     * 用户没有简历信息的添加简历信息
     * @param resume
     * @return
     */
    @PostMapping("/insert")
    public Result insertUserResume(@RequestBody Resume resume){
        log.info("需要添加的简历信息: {}" ,resume);
        return new Result(Code.SAVE_OK,resumeService.save(resume),Msg.SAVE_OK);
    }

    /**
     * 修改简历信息
     * @param resume
     * @return
     */

    @PutMapping("/update")
    public Result updateUserResume(@RequestBody Resume resume){
        LambdaUpdateWrapper<Resume> luw = new LambdaUpdateWrapper<>();
        luw.eq(Resume::getUser_id,resume.getUser_id());
        boolean update = resumeService.update(resume, luw);
        Integer code = update ? Code.UPDATE_OK : Code.UPDATE_ERR;
        String msg = update ? Msg.UPDATE_OK : Msg.UPDATE_ERR;
        return new Result(code,update,msg);
    }


}
